﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;

namespace NetROS.Tiers.Web.UI
{
    /// <summary>
    /// A designer class for a strongly typed repeater <c>VwObracunZaIDRepeater</c>
    /// </summary>
	public class VwObracunZaIDRepeaterDesigner : System.Web.UI.Design.ControlDesigner
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:VwObracunZaIDRepeaterDesigner"/> class.
        /// </summary>
		public VwObracunZaIDRepeaterDesigner()
		{
		}

        /// <summary>
        /// Initializes the control designer and loads the specified component.
        /// </summary>
        /// <param name="component">The control being designed.</param>
		public override void Initialize(IComponent component)
		{
			if (!(component is VwObracunZaIDRepeater))
			{ 
				throw new ArgumentException("Component is not a VwObracunZaIDRepeater."); 
			} 
			base.Initialize(component); 
			base.SetViewFlags(ViewFlags.TemplateEditing, true); 
		}


		/// <summary>
		/// Generate HTML for the designer
		/// </summary>
		/// <returns>a string of design time HTML</returns>
		public override string GetDesignTimeHtml()
		{

			// Get the instance this designer applies to
			//
			VwObracunZaIDRepeater z = (VwObracunZaIDRepeater)Component;
			z.DataBind();

			return base.GetDesignTimeHtml();

			//return z.RenderAtDesignTime();

			//	ControlCollection c = z.Controls;
			//Totem z = (Totem) Component;
			//Totem z = (Totem) Component;
			//return ("<div style='border: 1px gray dotted; background-color: lightgray'><b>TagStat :</b> zae |  qsdds</div>");

		}
	}

    /// <summary>
    /// A strongly typed repeater control for the <c cref="VwObracunZaIDRepeater"></c> Type.
    /// </summary>
	[Designer(typeof(VwObracunZaIDRepeaterDesigner))]
	[ParseChildren(true)]
	[ToolboxData("<{0}:VwObracunZaIDRepeater runat=\"server\"></{0}:VwObracunZaIDRepeater>")]
	public class VwObracunZaIDRepeater : Control, System.Web.UI.INamingContainer
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:VwObracunZaIDRepeater"/> class.
        /// </summary>
		public VwObracunZaIDRepeater()
		{
		}

		/// <summary>
        /// Gets a <see cref="T:System.Web.UI.ControlCollection"></see> object that represents the child controls for a specified server control in the UI hierarchy.
        /// </summary>
        /// <value></value>
        /// <returns>The collection of child controls for the specified server control.</returns>
		public override ControlCollection Controls
		{
			get
			{
				this.EnsureChildControls();
				return base.Controls;
			}
		}

		private ITemplate m_headerTemplate;
		/// <summary>
        /// Gets or sets the header template.
        /// </summary>
        /// <value>The header template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(VwObracunZaIDItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate HeaderTemplate
		{
			get { return m_headerTemplate; }
			set { m_headerTemplate = value; }
		}

		private ITemplate m_itemTemplate;
		/// <summary>
        /// Gets or sets the item template.
        /// </summary>
        /// <value>The item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(VwObracunZaIDItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate ItemTemplate
		{
			get { return m_itemTemplate; }
			set { m_itemTemplate = value; }
		}
			

		private ITemplate m_altenateItemTemplate;
        /// <summary>
        /// Gets or sets the alternating item template.
        /// </summary>
        /// <value>The alternating item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(VwObracunZaIDItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate AlternatingItemTemplate
		{
			get { return m_altenateItemTemplate; }
			set { m_altenateItemTemplate = value; }
		}

		private ITemplate m_footerTemplate;
        /// <summary>
        /// Gets or sets the footer template.
        /// </summary>
        /// <value>The footer template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(VwObracunZaIDItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate FooterTemplate
		{
			get { return m_footerTemplate; }
			set { m_footerTemplate = value; }
		}

        /// <summary>
        /// Gets or sets the data source ID.
        /// </summary>
        /// <value>The data source ID.</value>
		[Category("Data")]
		public virtual string DataSourceID
		{
			get
			{
				if (ViewState["DataSourceID"] == null)
				{
					return string.Empty;
				}
				return (string)ViewState["DataSourceID"];
			}
			set
			{
				ViewState["DataSourceID"] = value;
			}
		}

		//[Category("Data")]
		//public virtual string DataMember
		//{
		//    get
		//    {
		//        if (ViewState["DataMember"] == null)
		//        {
		//            return string.Empty;
		//        }
		//        return (string)ViewState["DataMember"];
		//    }
		//    set
		//    {
		//        ViewState["DataMember"] = value;
		//    }
		//}

		//private ProductDataSourceView m_currentView;

		System.Collections.IEnumerable m_currentView;
        /// <summary>
        /// Connects to data source view.
        /// </summary>
        /// <returns>an IEnumerable of DataSourceView</returns>
		private System.Collections.IEnumerable ConnectToDataSourceView()
		{
			if (m_currentView == null)
			{
				NetROS.Tiers.Web.Data.VwObracunZaIDDataSource datasource = null;
				//First look in the naming container
            Control ctl = this.NamingContainer.FindControl(DataSourceID);
            if (ctl == null)
            {
               //if not found, look at the page level
               ctl = this.Page.FindControl(DataSourceID);
               if (ctl == null)
               {
                  throw new System.Web.HttpException("Datasource does not exists");
               }
            }
				datasource = ctl as NetROS.Tiers.Web.Data.VwObracunZaIDDataSource;
				if (datasource == null)
				{
					throw new System.Web.HttpException("Datasource must be data control");
				}
				
				System.Collections.IEnumerable dsv = datasource.GetEntityList(); //this.DataMember);
				if (dsv == null)
				{
					throw new System.Web.HttpException("View not found");
				}
				m_currentView = dsv;
			}
			return m_currentView;
		}

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
		protected override void CreateChildControls()
		{
			if (ChildControlsCreated)
			{
				return;
			}
			Controls.Clear();

			System.Collections.IEnumerable datas = (System.Collections.IEnumerable)ConnectToDataSourceView();

			if (datas != null)
			{
				if (m_headerTemplate != null)
				{
					Control headerItem = new Control();
					m_headerTemplate.InstantiateIn(headerItem);
					Controls.Add(headerItem);
				}

				int pos = 0;
				foreach (object o in datas)
				{
					NetROS.Tiers.Entities.VwObracunZaID entity = o as NetROS.Tiers.Entities.VwObracunZaID;
					VwObracunZaIDItem container = new VwObracunZaIDItem(entity);

					if (m_itemTemplate != null && (pos % 2) == 0)
					{
						m_itemTemplate.InstantiateIn(container);
					}
					else
					{
						if (m_altenateItemTemplate != null)
						{
							m_altenateItemTemplate.InstantiateIn(container);
						}
						else if (m_itemTemplate != null)
						{
							m_itemTemplate.InstantiateIn(container);
						}
						else
						{
							// no template !!!
						}
					}
					Controls.Add(container);
					pos++;
				}

				if (m_footerTemplate != null)
				{
					Control footerItem = new Control();
					m_footerTemplate.InstantiateIn(footerItem);
					Controls.Add(footerItem);
				}
				ChildControlsCreated = true;
			}
		}
		
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> object that contains the event data.</param>
		protected override void OnPreRender(EventArgs e)
		{
			base.DataBind();
		}

		#region Design time
        /// <summary>
        /// Renders at design time.
        /// </summary>
        /// <returns>a  string of the Designed HTML</returns>
		internal string RenderAtDesignTime()
		{			
			return "Designer currently not implemented"; 
		}

		#endregion
	}

    /// <summary>
    /// A wrapper type for the entity
    /// </summary>
	[System.ComponentModel.ToolboxItem(false)]
	public class VwObracunZaIDItem : System.Web.UI.Control, System.Web.UI.INamingContainer
	{
		private NetROS.Tiers.Entities.VwObracunZaID _entity;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:VwObracunZaIDItem"/> class.
        /// </summary>
		public VwObracunZaIDItem()
			: base()
		{ }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:VwObracunZaIDItem"/> class.
        /// </summary>
		public VwObracunZaIDItem(NetROS.Tiers.Entities.VwObracunZaID entity)
			: base()
		{
			_entity = entity;
		}
		
        /// <summary>
        /// Gets the IDObracun
        /// </summary>
        /// <value>The IDObracun.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 IDObracun
		{
			get { return _entity.IDObracun; }
		}
        /// <summary>
        /// Gets the Naziv
        /// </summary>
        /// <value>The Naziv.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String Naziv
		{
			get { return _entity.Naziv; }
		}
        /// <summary>
        /// Gets the Sjediste
        /// </summary>
        /// <value>The Sjediste.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String Sjediste
		{
			get { return _entity.Sjediste; }
		}
        /// <summary>
        /// Gets the IPPU
        /// </summary>
        /// <value>The IPPU.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String IPPU
		{
			get { return _entity.IPPU; }
		}
        /// <summary>
        /// Gets the IBObveznika
        /// </summary>
        /// <value>The IBObveznika.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String IBObveznika
		{
			get { return _entity.IBObveznika; }
		}
        /// <summary>
        /// Gets the IdentifikatorIDNaziv
        /// </summary>
        /// <value>The IdentifikatorIDNaziv.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String IdentifikatorIDNaziv
		{
			get { return _entity.IdentifikatorIDNaziv; }
		}
        /// <summary>
        /// Gets the IdentifikatorIDSifra
        /// </summary>
        /// <value>The IdentifikatorIDSifra.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String IdentifikatorIDSifra
		{
			get { return _entity.IdentifikatorIDSifra; }
		}
        /// <summary>
        /// Gets the RSMVrstaObracunaOpis
        /// </summary>
        /// <value>The RSMVrstaObracunaOpis.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String RSMVrstaObracunaOpis
		{
			get { return _entity.RSMVrstaObracunaOpis; }
		}
        /// <summary>
        /// Gets the RSMVrstaObracunaSifra
        /// </summary>
        /// <value>The RSMVrstaObracunaSifra.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String RSMVrstaObracunaSifra
		{
			get { return _entity.RSMVrstaObracunaSifra; }
		}
        /// <summary>
        /// Gets the RSMVrstaObveznikaOpis
        /// </summary>
        /// <value>The RSMVrstaObveznikaOpis.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String RSMVrstaObveznikaOpis
		{
			get { return _entity.RSMVrstaObveznikaOpis; }
		}
        /// <summary>
        /// Gets the RSMVrstaObveznikaSifra
        /// </summary>
        /// <value>The RSMVrstaObveznikaSifra.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String RSMVrstaObveznikaSifra
		{
			get { return _entity.RSMVrstaObveznikaSifra; }
		}
        /// <summary>
        /// Gets the UkBrojStranica
        /// </summary>
        /// <value>The UkBrojStranica.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64? UkBrojStranica
		{
			get { return _entity.UkBrojStranica; }
		}
        /// <summary>
        /// Gets the UkBrojOsoba
        /// </summary>
        /// <value>The UkBrojOsoba.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64? UkBrojOsoba
		{
			get { return _entity.UkBrojOsoba; }
		}
        /// <summary>
        /// Gets the IsplaceniPrimici
        /// </summary>
        /// <value>The IsplaceniPrimici.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? IsplaceniPrimici
		{
			get { return _entity.IsplaceniPrimici; }
		}
        /// <summary>
        /// Gets the MIO1
        /// </summary>
        /// <value>The MIO1.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO1
		{
			get { return _entity.MIO1; }
		}
        /// <summary>
        /// Gets the MIO2
        /// </summary>
        /// <value>The MIO2.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO2
		{
			get { return _entity.MIO2; }
		}
        /// <summary>
        /// Gets the Dohodak
        /// </summary>
        /// <value>The Dohodak.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? Dohodak
		{
			get { return _entity.Dohodak; }
		}
        /// <summary>
        /// Gets the OsobniOdbici
        /// </summary>
        /// <value>The OsobniOdbici.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? OsobniOdbici
		{
			get { return _entity.OsobniOdbici; }
		}
        /// <summary>
        /// Gets the PorOsnovica
        /// </summary>
        /// <value>The PorOsnovica.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? PorOsnovica
		{
			get { return _entity.PorOsnovica; }
		}
        /// <summary>
        /// Gets the ObracunatPorezIPrirez
        /// </summary>
        /// <value>The ObracunatPorezIPrirez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? ObracunatPorezIPrirez
		{
			get { return _entity.ObracunatPorezIPrirez; }
		}
        /// <summary>
        /// Gets the ObracunatPorez
        /// </summary>
        /// <value>The ObracunatPorez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? ObracunatPorez
		{
			get { return _entity.ObracunatPorez; }
		}
        /// <summary>
        /// Gets the ObracunatPrirez
        /// </summary>
        /// <value>The ObracunatPrirez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? ObracunatPrirez
		{
			get { return _entity.ObracunatPrirez; }
		}
        /// <summary>
        /// Gets the BrojRadnika
        /// </summary>
        /// <value>The BrojRadnika.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? BrojRadnika
		{
			get { return _entity.BrojRadnika; }
		}
        /// <summary>
        /// Gets the MIO1Osnovno
        /// </summary>
        /// <value>The MIO1Osnovno.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO1Osnovno
		{
			get { return _entity.MIO1Osnovno; }
		}
        /// <summary>
        /// Gets the MIO1Povecano
        /// </summary>
        /// <value>The MIO1Povecano.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO1Povecano
		{
			get { return _entity.MIO1Povecano; }
		}
        /// <summary>
        /// Gets the MIO2Osnovno
        /// </summary>
        /// <value>The MIO2Osnovno.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO2Osnovno
		{
			get { return _entity.MIO2Osnovno; }
		}
        /// <summary>
        /// Gets the MIO2Povecano
        /// </summary>
        /// <value>The MIO2Povecano.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? MIO2Povecano
		{
			get { return _entity.MIO2Povecano; }
		}
        /// <summary>
        /// Gets the Zdrav
        /// </summary>
        /// <value>The Zdrav.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? Zdrav
		{
			get { return _entity.Zdrav; }
		}
        /// <summary>
        /// Gets the ZastitaNaRadu
        /// </summary>
        /// <value>The ZastitaNaRadu.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? ZastitaNaRadu
		{
			get { return _entity.ZastitaNaRadu; }
		}
        /// <summary>
        /// Gets the Zaposljavanje
        /// </summary>
        /// <value>The Zaposljavanje.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? Zaposljavanje
		{
			get { return _entity.Zaposljavanje; }
		}
        /// <summary>
        /// Gets the Invaliditet
        /// </summary>
        /// <value>The Invaliditet.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? Invaliditet
		{
			get { return _entity.Invaliditet; }
		}
        /// <summary>
        /// Gets the ZdrInozemstvo
        /// </summary>
        /// <value>The ZdrInozemstvo.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? ZdrInozemstvo
		{
			get { return _entity.ZdrInozemstvo; }
		}
        /// <summary>
        /// Gets the UkNetoPredPosPorez
        /// </summary>
        /// <value>The UkNetoPredPosPorez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? UkNetoPredPosPorez
		{
			get { return _entity.UkNetoPredPosPorez; }
		}
        /// <summary>
        /// Gets the UkNetoIsplata
        /// </summary>
        /// <value>The UkNetoIsplata.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? UkNetoIsplata
		{
			get { return _entity.UkNetoIsplata; }
		}
        /// <summary>
        /// Gets the UkPosPorez
        /// </summary>
        /// <value>The UkPosPorez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? UkPosPorez
		{
			get { return _entity.UkPosPorez; }
		}
        /// <summary>
        /// Gets the DatumIsplate
        /// </summary>
        /// <value>The DatumIsplate.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime DatumIsplate
		{
			get { return _entity.DatumIsplate; }
		}
        /// <summary>
        /// Gets the DatumOd
        /// </summary>
        /// <value>The DatumOd.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime DatumOd
		{
			get { return _entity.DatumOd; }
		}
        /// <summary>
        /// Gets the DatumDo
        /// </summary>
        /// <value>The DatumDo.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime DatumDo
		{
			get { return _entity.DatumDo; }
		}
        /// <summary>
        /// Gets the RedniBrojUGodini
        /// </summary>
        /// <value>The RedniBrojUGodini.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 RedniBrojUGodini
		{
			get { return _entity.RedniBrojUGodini; }
		}
        /// <summary>
        /// Gets the ObracunMjesec
        /// </summary>
        /// <value>The ObracunMjesec.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? ObracunMjesec
		{
			get { return _entity.ObracunMjesec; }
		}
        /// <summary>
        /// Gets the ObracunGodina
        /// </summary>
        /// <value>The ObracunGodina.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? ObracunGodina
		{
			get { return _entity.ObracunGodina; }
		}
        /// <summary>
        /// Gets the IsplataMjesec
        /// </summary>
        /// <value>The IsplataMjesec.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? IsplataMjesec
		{
			get { return _entity.IsplataMjesec; }
		}
        /// <summary>
        /// Gets the IsplataGodina
        /// </summary>
        /// <value>The IsplataGodina.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? IsplataGodina
		{
			get { return _entity.IsplataGodina; }
		}
        /// <summary>
        /// Gets the RSMSHA
        /// </summary>
        /// <value>The RSMSHA.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String RSMSHA
		{
			get { return _entity.RSMSHA; }
		}
        /// <summary>
        /// Gets the BrojOsobaSPosPorezom
        /// </summary>
        /// <value>The BrojOsobaSPosPorezom.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32? BrojOsobaSPosPorezom
		{
			get { return _entity.BrojOsobaSPosPorezom; }
		}
        /// <summary>
        /// Gets the PorOsnovicaPosPorez
        /// </summary>
        /// <value>The PorOsnovicaPosPorez.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Decimal? PorOsnovicaPosPorez
		{
			get { return _entity.PorOsnovicaPosPorez; }
		}

	}
}
